package proto

import (
	"regexp"
	D "websocket_apn/define"
	"websocket_apn/log"
)

/*
08 03 12 05 08 DE 23 10 02 18 00 22 08 08 E0 86 03 10 01 18 01 28 C1 E4 AD FA AB 32
{R1:3 R2:4574 R3:2 R4:0 Layer:50016 ChallengeNum:7 R7:1 Time:2024-10-25 00:10:45.697 +0800 CST}
无速战
*/
//道途试练
func ParaDaoTuInfo(dataBytes []byte) D.DaoTuInfo {
	var info D.DaoTuInfo
	data := BytesToHexStr(dataBytes)
	// 									1
	re := regexp.MustCompile(`08([0-9A-F]{2})12[0-9A-F]{2}08([0-9A-F]{4})10([0-9A-F]{2})18([0-9A-F]{2})22[0-9A-F]{2}08([0-9A-F]{6})10([0-9A-F]{2})18([0-9A-F]{2})28([0-9A-F]{12})`)
	res := re.FindAllStringSubmatch(data, -1)
	if len(res) == 0 {
		log.Errorf("解析数据失败-%s", data)
	}
	// 打印结果
	for _, regRes := range res {
		info = D.DaoTuInfo{
			R1:           OneByteHexStrToByte(regRes[1]),
			R2:           int(ParaIntDataByHexStr(regRes[2])),
			R3:           OneByteHexStrToByte(regRes[3]),
			R4:           OneByteHexStrToByte(regRes[4]),
			Layer:        int(ParaIntDataByHexStr(regRes[5])),
			ChallengeNum: OneByteHexStrToByte(regRes[6]),
			R7:           OneByteHexStrToByte(regRes[7]),
			Time:         ParaHexStrToTimeMs(regRes[8]),
		}
	}
	log.Infof("道途试练-%+v", info)
	return info
}
